//
//  ReleaseMainVC.m
//  SelfDriving
//
//  Created by apple on 16/2/1.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ReleaseMainVC.h"
#import "XLSwitchView.h"
#import "ReleaseCircleVC.h"
#import "ReleaseFollowVC.h"
#import "AddMapViewController.h"
#import "IQKeyboardManager.h"
#import "AddFileViewController.h"
#import "XhwWebViewController.h"


@interface ReleaseMainVC ()<XLSwitchViewDelegate,AddMapViewControllerDatalete>
@property (strong, nonatomic) XLSwitchView *switchViews;

@property(nonatomic, strong) AddFileViewController *addFileVC;

@end

@implementation ReleaseMainVC{
    int indexs;
    int islod;
}
- (void)viewDidLoad {
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(backActino:)
     name:@"backAction"
     object:nil];
    
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(tomap:)
     name:@"tomap"
     object:nil];
    
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(tophoto:)
     name:@"tophoto"
     object:nil];
    
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = NO;
    indexs = 100;
    _switchViews = [[XLSwitchView alloc] initWithFrame:CGRectMake(0,44,SCRE_WIDTH,SCRE_HEIGHT-54)];
    _switchViews.backgroundColor = [UIColor clearColor];
    _switchViews.delegate = self;
    _switchViews.btnWidth = SCRE_WIDTH/2;
    _switchViews.btncolor = UIColorFromRGB(0x1DA24A);
    _switchViews.inecolor = UIColorFromRGB(0x1DA24A);
    [_switchViews createUserInterface];
    UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 64, SCRE_WIDTH/2, 44)];
    [btn1 setTitle:@"" forState:UIControlStateNormal];
    [self.view addSubview:btn1];
    UIButton *btn2 = [[UIButton alloc]initWithFrame:CGRectMake(SCRE_WIDTH/2, 64, SCRE_WIDTH/2, 44)];
    [btn2 setTitle:@"" forState:UIControlStateNormal];
    [self.view addSubview:btn2];
    [self.view addSubview:_switchViews];
}
#pragma mark 设置当前界面不使用IQ

-(void)viewWillDisappear:(BOOL)animated
{
    [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
    [IQKeyboardManager sharedManager].enable = YES;
}
-(void)viewWillAppear:(BOOL)animated{
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
    [IQKeyboardManager sharedManager].enable = NO;
}
-(void)tophoto:(NSNotification *)not{

    if (![AppDelegate shareDelegate].islod) {
        [AppDelegate shareDelegate].islod = NO;
        self.addFileVC.presentVC = self;
        [self presentViewController:self.addFileVC animated:YES completion:nil];
    }else {
        [SVProgressHUD showWithStatus:@"请设置打开相册"];
    }
}
-(void)tomap:(NSNotification *)not {
    NSLog(@"熊宏伟-ReleaseMainVC-tomap通知");
    UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"MS"
                                                                 bundle:[NSBundle mainBundle]];
    AddMapViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"AddMapVC"];
    searchResultDetailController.datelate = self;
    [self.navigationController pushViewController:searchResultDetailController animated:YES];
    NSLog(@"%@",[self.navigationController viewControllers]);
    NSLog(@"%lu",[self.navigationController viewControllers].count);
}
#pragma mark 地图选择回调
-(void)selectAddress:(NSMutableDictionary *)address{
    [[NSNotificationCenter defaultCenter ] postNotificationName:@"getmap" object:address];
}
-(NSInteger)numberOfItemsInSwitchView:(XLSwitchView *)switchView{
    return 2;
}
-(UIViewController *)switchView:(XLSwitchView *)switchView withViewOfItem:(NSInteger)index{
    if (index == 0) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Dynaminc" bundle:nil];
        ReleaseFollowVC *vc = [storyboard instantiateViewControllerWithIdentifier:@"ReleaseFollowVC"];
        //xhw2018-1-21加
        if (_ADUrl) {
            vc.adUrl = _ADUrl;
        }
        //xhw2018-1-12加
        vc.mainCtrl = self;
        if (_imgData) {
            vc.imgData = _imgData;
        }
        if (_videoUrl) {
            vc.videoUrl = _videoUrl;
        }
        vc.title = @"关注者";
        return vc;
    }else{
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Dynaminc" bundle:nil];
        ReleaseCircleVC *vc = [storyboard instantiateViewControllerWithIdentifier:@"ReleaseCircleVC"];
        //xhw2018-1-12加
        vc.mainCtrl = self;
        if (_imgData) {
            vc.imgData = _imgData;
        }
        if (_videoUrl) {
            vc.videoUrl = _videoUrl;
        }
        vc.title = @"圈人";
        return vc;
    }
    
    
}
-(void)ScrollAction:(NSInteger)index{
    indexs = (int)index ;
    
}
- (IBAction)submitAction:(UIBarButtonItem *)sender {
    if (indexs==100) {
        [[NSNotificationCenter defaultCenter ]postNotificationName:@"submitAction" object:nil];
    }else{
        [[NSNotificationCenter defaultCenter ]postNotificationName:@"submitActions" object:nil];
    }

    
}
- (IBAction)backActino:(id)sender {
//    [self.navigationController popViewControllerAnimated:YES];
    UIViewController * ctrl = self.navigationController.viewControllers[self.navigationController.viewControllers.count-2];
    if ([ctrl isKindOfClass:[XhwWebViewController class]]) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    else {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
//    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (AddFileViewController *)addFileVC {
    if (!_addFileVC) {
        UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"Dynaminc"
                                                                     bundle:[NSBundle mainBundle]];
        _addFileVC = [customerStoryboard instantiateViewControllerWithIdentifier:@"AddFileViewController"];
        _addFileVC.InType = 1;
    }
    return _addFileVC;
}
@end
